package com.xbongbong.crm.perform.query.detail;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.crm.abstracts.AbstractCrmDetailTopInfoService;
import com.xbongbong.crm.service.permission.QuotationPermissionServiceImpl;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.enums.UnitEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkListPojo;
import com.xbongbong.paas.help.EsignHelp;
import com.xbongbong.paas.help.OwnerAndCoUserHelp;
import com.xbongbong.paas.model.PaasMenuModel;
import com.xbongbong.paas.pojo.ButtonPojo;
import com.xbongbong.paas.pojo.CustomerUserPojo;
import com.xbongbong.paas.pojo.DataDetailPojo;
import com.xbongbong.paas.pojo.FormTitlePoJo;
import com.xbongbong.paas.pojo.HandelDetailPojo;
import com.xbongbong.paas.pojo.SummaryDataPoJo;
import com.xbongbong.paas.pojo.WorkFlowPojo;
import com.xbongbong.paas.pojo.vo.FormDataGetVO;
import com.xbongbong.paas.pojo.vo.ParseSingleRowDataVO;
import com.xbongbong.paas.service.BusinessButtonService;
import com.xbongbong.paas.service.LinkListService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.paas.util.TitleUtil;
import com.xbongbong.parent.explain.FormDataDetailFormExplainHandleName;
import com.xbongbong.parent.parse.data.FormDataGetAnalysisDataHelp;
import com.xbongbong.pro.appdetail.pojo.MobileDetailManagerBlockPojo;
import com.xbongbong.pro.appdetail.pojo.MobileDetailMoneyItemPojo;
import com.xbongbong.pro.appdetail.pojo.MobileDetailScriptPojo;
import com.xbongbong.pro.appdetail.pojo.MobileDetailStatusBlockPojo;
import com.xbongbong.pro.appdetail.pojo.MobileDetailStatusPojo;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.enums.permission.enums.UpdateProPermissionAliasEnum;
import com.xbongbong.pro.form.pojo.TopPermissionsPoJo;
import com.xbongbong.pro.formdata.pojo.dto.FormDataDetailDTO;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainDTO;
import com.xbongbong.pro.formexplain.pojo.vo.HandlerExplainVO;
import com.xbongbong.pro.message.model.PushModel;
import com.xbongbong.pro.permission.pojo.dto.VerifyViewPermissionDTO;
import com.xbongbong.process.operate.ProcessFieldHelp;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.domain.entity.QuotationUserEntity;
import com.xbongbong.saas.enums.BusinessDetailButtonEnum;
import com.xbongbong.saas.enums.OperateTypeEnum;
import com.xbongbong.saas.enums.SaasButtonEnum;
import com.xbongbong.saas.enums.WorkFlowEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import com.xbongbong.saas.enums.business.QuotationEnum;
import com.xbongbong.saas.enums.dictionary.ArchivedEnum;
import com.xbongbong.saas.model.QuotationModel;
import com.xbongbong.saas.model.QuotationUserModel;
import com.xbongbong.saas.service.toolbox.help.AttrDecimalPrecisionHelper;
import com.xbongbong.saas.service.toolbox.help.UserTeamHelp;
import com.xbongbong.saas.toolbox.help.FastJsonHelper;
import com.xbongbong.sys.domain.entity.UserEntity;
import com.xbongbong.sys.model.UserModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static com.xbongbong.saas.toolbox.help.FastJsonHelper.getIntegerOrDefaultFromFormData;
import static com.xbongbong.util.NameUtil.changeValue;

/**
 * @author 吴峰
 * @date 2022/06/13 9:17
 */
@Service("quotationDetailTopInfoServiceImpl")
@Slf4j
public class QuotationDetailTopInfoServiceImpl extends AbstractCrmDetailTopInfoService {

    @Resource
    private QuotationPermissionServiceImpl quotationPermissionService;
    @Resource
    private OwnerAndCoUserHelp ownerAndCoUserHelp;
    @Resource
    private FormDataDetailFormExplainHandleName formDataDetailFormExplainHandleName;
    @Resource
    private QuotationModel quotationModel;
    @Resource
    private FormDataGetAnalysisDataHelp formDataGetAnalysisDataHelp;
    @Resource
    private PaasMenuModel paasMenuModel;
    @Resource
    private EsignHelp esignHelp;
    @Resource
    private QuotationUserModel quotationUserModel;
    @Resource
    private UserModel userModel;
    @Resource
    private ProcessFieldHelp processFieldHelp;
    @Resource
    private PushModel pushModel;
    @Resource
    private UserTeamHelp userTeamHelp;
    @Resource
    private BusinessButtonService businessButtonService;
    @Resource
    private LinkListService linkListService;


    @Override
    public List<Integer> businessType() {
        return Arrays.asList(XbbRefTypeEnum.QUOTATION.getCode());
    }

    @Override
    public void checkPermission(PaasFormEntityExt formEntity, PaasFormDataEntityExt paasFormDataEntityExt, UserVO loginUser, Integer subBusinessType) throws XbbException {
        if (loginUser.isMaxDataPermission()){
            return;
        }
        //校验用户是否有查看权限
        verifyQueryPermission(formEntity.getBusinessType(), loginUser, formEntity.getSaasMark(), formEntity.getMenuId(), paasFormDataEntityExt.getFlowStatus());
        //团队权限&共享权限校验
        quotationPermissionService.checkPermission(formEntity, paasFormDataEntityExt, loginUser, subBusinessType);
    }


    @Override
    public JSONObject analysisData(PaasFormDataEntityExt paasFormDataEntityExt, HandlerExplainDTO handlerExplainDTO, HandlerExplainVO handlerExplainVO) throws XbbException {
        Long formId = paasFormDataEntityExt.getFormId();
        List<FieldAttrEntity> list = handlerExplainVO.getHeadList();
        Map<String, FieldAttrEntity> explainMap = new HashMap<>(list.size());
        list.forEach(item->explainMap.put(item.getAttr(), item));

        ParseSingleRowDataVO parseSingleRowDataVO = commonAnalysisData(paasFormDataEntityExt, handlerExplainDTO, handlerExplainVO, list, explainMap);
        JSONObject data = parseSingleRowDataVO.getResult();
        SaasAnalysisDataDTO saasAnalysisDataDTO = new SaasAnalysisDataDTO();
        BeanUtil.copyProperties(handlerExplainDTO, saasAnalysisDataDTO);
        saasAnalysisDataDTO.setFormId(formId);
        quotationModel.formatData(saasAnalysisDataDTO, data);
        //处理千分位
        FormDataGetVO formDataGetVO = new FormDataGetVO();
        formDataGetVO.setData(data);
        formDataGetAnalysisDataHelp.analysisGetOfThousandBits(formDataGetVO, list, false);
        return data;
    }

    @Override
    public List<MobileDetailMoneyItemPojo> getMobileDetailMoneyInfo(Integer distributorMark, String corpid, String userId, Integer businessType, Integer subBusinessType, Long dataId, JSONObject data, Map<String, FieldAttrEntity> explainMap, UserVO loginUser, PaasFormDataEntityExt paasFormDataEntityExt) throws XbbException {
        FieldAttrEntity quotationAmountFieldAttrEntity = explainMap.get(QuotationEnum.AMOUNT.getAttr());
        String unitStr = UnitEnum.MONEY.getName();
        List<MobileDetailMoneyItemPojo> moneyItemList = new ArrayList<>();
        if (Objects.nonNull(quotationAmountFieldAttrEntity) && Objects.equals(quotationAmountFieldAttrEntity.getVisible(), BasicConstant.ONE)) {
            Object contractAmount = AttrDecimalPrecisionHelper.moneyParseThrousandth(quotationAmountFieldAttrEntity, paasFormDataEntityExt.getData(),QuotationEnum.AMOUNT.getAttr());
            moneyItemList.add(new MobileDetailMoneyItemPojo(quotationAmountFieldAttrEntity.getAttrName() + "/" + unitStr, contractAmount, false));
        }

        FieldAttrEntity quotationDiscountFieldAttrEntity = explainMap.get(QuotationEnum.DISCOUNT.getAttr());
        if (Objects.nonNull(quotationDiscountFieldAttrEntity) && Objects.equals(quotationDiscountFieldAttrEntity.getVisible(), BasicConstant.ONE)) {
            String quotationDiscount = data.getString(QuotationEnum.DISCOUNT.getAttr());
            moneyItemList.add(new MobileDetailMoneyItemPojo(quotationDiscountFieldAttrEntity.getAttrName() + "/%", quotationDiscount, false));
        }

        FieldAttrEntity quotationEstimateCostFieldAttrEntity = explainMap.get(QuotationEnum.ESTIMATE_COST.getAttr());
        if (Objects.nonNull(quotationEstimateCostFieldAttrEntity) && Objects.equals(quotationEstimateCostFieldAttrEntity.getVisible(), BasicConstant.ONE)) {
            Object estimateCost = data.getString(QuotationEnum.ESTIMATE_COST.getAttr());
            moneyItemList.add(new MobileDetailMoneyItemPojo(quotationEstimateCostFieldAttrEntity.getAttrName() + "/" + unitStr, estimateCost ,false));
        }

        FieldAttrEntity quotationCostFieldAttrEntity = explainMap.get(QuotationEnum.ESTIMATE_COST.getAttr());
        if (Objects.nonNull(quotationCostFieldAttrEntity) && Objects.equals(quotationCostFieldAttrEntity.getVisible(), BasicConstant.ONE)) {
            Object contractCost = AttrDecimalPrecisionHelper.moneyParseThrousandth(quotationCostFieldAttrEntity,data, ContractEnum.ESTIMATE_COST.getAttr());
            moneyItemList.add(new MobileDetailMoneyItemPojo(quotationCostFieldAttrEntity.getAttrName() + "/" + unitStr, contractCost, false));
        }
        FieldAttrEntity quotationGrossFieldAttrEntity = explainMap.get(QuotationEnum.GROSS_PROFIT.getAttr());
        if (Objects.nonNull(quotationGrossFieldAttrEntity) && Objects.equals(quotationGrossFieldAttrEntity.getVisible(), BasicConstant.ONE)) {
            Object contractGrossProfit = AttrDecimalPrecisionHelper.moneyParseThrousandth(quotationGrossFieldAttrEntity,data,QuotationEnum.GROSS_PROFIT.getAttr());
            moneyItemList.add(new MobileDetailMoneyItemPojo(quotationGrossFieldAttrEntity.getAttrName() + "/" + unitStr, contractGrossProfit, false));
        }

        FieldAttrEntity quotationGrossProfitRateFieldAttrEntity = explainMap.get(QuotationEnum.GROSS_PROFIT_RATE.getAttr());
        if (Objects.nonNull(quotationGrossProfitRateFieldAttrEntity) && Objects.equals(quotationGrossProfitRateFieldAttrEntity.getVisible(), BasicConstant.ONE)) {
            String quotationGrossProfitRateStr = data.getString(QuotationEnum.GROSS_PROFIT_RATE.getAttr());
            moneyItemList.add(new MobileDetailMoneyItemPojo(quotationGrossProfitRateFieldAttrEntity.getAttrName() + "/%", quotationGrossProfitRateStr, false));
        }
        return moneyItemList;
    }

    @Override
    public JSONArray getBottomBlockInfo(String corpid, String userId, Integer businessType, PaasFormEntityExt formEntity, Long dataId, JSONObject data, Map<String, FieldAttrEntity> explainMap, PaasFormDataEntityExt entityExt, HandlerExplainDTO handlerExplainDTO) throws XbbException {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("corpid", corpid);
        param.put("del", 0);
        param.put("quotationId", dataId);
        List<QuotationUserEntity> quotationUserEntities = quotationUserModel.findEntitys(param);
        Set<String> userIdIn = new HashSet<>();
        quotationUserEntities.forEach(item-> userIdIn.add(item.getUserId()));
        List<UserEntity> userEntityList = userModel.getByUserIdIn(corpid, userIdIn, true);
        Map<String, UserEntity> userMap = new HashMap<>(userEntityList.size());
        userEntityList.forEach(item -> userMap.put(item.getUserId(), item));
        List<CustomerUserPojo> userPojoList = new ArrayList<>();
        quotationUserEntities.forEach(item -> {
            UserEntity userEntity = userMap.get(item.getUserId());
            if (userEntity != null) {
                CustomerUserPojo quotationUserPojo = new CustomerUserPojo();
                quotationUserPojo.setUserId(userEntity.getUserId());
                quotationUserPojo.setName(userEntity.getName());
                quotationUserPojo.setAvatar(userEntity.getAvatar());
                quotationUserPojo.setIsMain(item.getIsMain());
                userPojoList.add(quotationUserPojo);
            }
        });
        JSONArray bottomBlockInfo = new JSONArray();
        bottomBlockInfo.add(new MobileDetailManagerBlockPojo(userPojoList));
        FieldAttrEntity attrEntity = explainMap.get(QuotationEnum.STATUS.getAttr());
        if (attrEntity != null) {
            List<ItemPoJo> items = attrEntity.getItems();
            String quotationStatus = FastJsonHelper.getStringOrDefaultFromFormData(entityExt.getData(), QuotationEnum.STATUS.getAttr(), "");
            items.forEach(itemPoJo -> {
                if (Objects.equals(itemPoJo.getValue(), quotationStatus)) {
                    itemPoJo.setChecked(true);
                } else {
                    itemPoJo.setChecked(false);
                }
            });
            MobileDetailStatusBlockPojo statusBlockPojo = new MobileDetailStatusBlockPojo();
            Integer editAfterFinish = processFieldHelp.isEditable(corpid, explainMap, entityExt.getAppId(), entityExt.getFormId(), entityExt.getFlowStatus(),  QuotationEnum.STATUS.getAttr(), handlerExplainDTO);
            statusBlockPojo.setEditable(editAfterFinish);
            statusBlockPojo.setOptions(items);
            bottomBlockInfo.add(statusBlockPojo);
        }
        return bottomBlockInfo;
    }

    @Override
    public List<MobileDetailScriptPojo> getDetailShowScript(Integer businessType, UserVO loginUser, PaasFormDataEntityExt paasFormDataEntityExt, Map<String, FieldAttrEntity> explainMap) throws XbbException {
        return new ArrayList<>();
    }

    @Override
    public MobileDetailStatusPojo getDetailShowStatus(Integer businessType, JSONObject data) throws XbbException {
        MobileDetailStatusPojo mobileDetailStatusPojo = new MobileDetailStatusPojo();
        Integer quotationArchived = getIntegerOrDefaultFromFormData(data, QuotationEnum.ARCHIVED.getAttr(), 2);
        mobileDetailStatusPojo.setName("archived");
        mobileDetailStatusPojo.setValue(quotationArchived);
        return mobileDetailStatusPojo;
    }

    @Override
    public Map<String, Object> getDetailShowOperation(String corpid, String userId, Integer businessType, Long dataId, JSONObject data) throws XbbException {
        //有提醒的报价单
       List<Long> pushNotifyList = new ArrayList<>();

        pushModel.getPushNotify(Collections.singletonList(dataId), corpid, XbbRefTypeEnum.QUOTATION.getCode(), pushNotifyList);
        Map<String, Object> param = new HashMap<>(BasicConstant.ONE);
        if (!pushNotifyList.isEmpty()) {
            param.put("message", true);
        }
        return param;
    }

    @Override
    public JSONObject returnSaasObject(String corpid, Integer businessType, UserVO userVO, PaasFormDataEntityExt paasFormDataEntityExt) throws XbbException {
        return new JSONObject();
    }

    @Override
    public List<TopPermissionsPoJo> dingtalkHandleDetailWorkFlow(HandelDetailPojo handelDetailPojo, PaasFormEntityExt formEntity, PaasFormDataEntityExt formData, Map<String, FieldAttrEntity> explainMap) throws XbbException {
        JSONObject dataList = formData.getData();
        Integer quotationArchived = getIntegerOrDefaultFromFormData(dataList, QuotationEnum.ARCHIVED.getAttr(), ArchivedEnum.UN_ARCHIVED.getCode());
        Integer isNew = getIntegerOrDefaultFromFormData(dataList, QuotationEnum.IS_NEW.getAttr(), BasicConstant.ONE);
        Set<String> loginUserPermSet =  handelDetailPojo.getLoginUser().getPermSet();
        String corpid = formEntity.getCorpid();
        UserVO userVO = handelDetailPojo.getLoginUser();
        Integer businessType = formEntity.getBusinessType();
        List<WorkFlowEnum> workFlowEnumList = WorkFlowEnum.getByBusinessTypeAndPermissionForDingtalk(businessType, userVO.getPermSet());

        List<String> aliasIn = new ArrayList<>();
        workFlowEnumList.forEach(item -> aliasIn.add(XbbRefTypeEnum.getByCode(item.getBusinessType()).getAlias()));
        Map<Integer, String> paasBusinessTypeToName = paasMenuModel.getMenuNameByAlias(aliasIn, corpid, businessType);
        UpdateProPermissionAliasEnum updateProPermissionAliasEnum = UpdateProPermissionAliasEnum.getByCode(businessType);

        FormDataDetailDTO formDataDetailDTO = new FormDataDetailDTO();
        formDataDetailDTO.setLoginUser(userVO);
        formDataDetailDTO.setSaasMark(formEntity.getSaasMark());
        formDataDetailDTO.setBusinessType(formEntity.getBusinessType());
        formDataDetailDTO.setMenuId(formEntity.getMenuId());
        formDataDetailDTO.setDistributorMark(formEntity.getDistributorMark());

        //获取编辑权限(归档按钮需要判断,单独放外边)
        boolean hasFormEditPermission = userVO.getPermSet().contains(updateProPermissionAliasEnum.getAlias());
        VerifyViewPermissionDTO verifyViewPermissionDTO = new VerifyViewPermissionDTO(userVO, formData);
        boolean hasDataEditpermission = commonPermissionHelp.checkEditPermissionWithoutShareEdit(formDataDetailDTO, verifyViewPermissionDTO, explainMap);
        boolean hasUpdate = hasFormEditPermission && hasDataEditpermission;

        List<TopPermissionsPoJo> topPermissions = businessButtonService.dingtalkDetailCommon(userVO, formEntity, explainMap, formData);
        for (WorkFlowEnum workFlowEnum : workFlowEnumList) {

            List<WorkFlowPojo> workFlowPojoList = new ArrayList<>();
            if (esignHelp.addEsignWorkFlow(loginUserPermSet, workFlowPojoList, workFlowEnum,
                    XbbRefTypeEnum.QUOTATION, formData)) {
                if (workFlowPojoList.isEmpty()) {
                    continue;
                }
            }

            if (!hasUpdate && (Objects.equals(workFlowEnum, WorkFlowEnum.QUOTATION_ARCHIVED) || Objects.equals(workFlowEnum, WorkFlowEnum.QUOTATION_CANCEL_ARCHIVED))) {
                continue;
            }
            if (Objects.equals(quotationArchived, ArchivedEnum.ARCHIVED.getCode()) && Objects.equals(workFlowEnum, WorkFlowEnum.QUOTATION_ARCHIVED)) {
                continue;
            }
            if (Objects.equals(quotationArchived, ArchivedEnum.UN_ARCHIVED.getCode()) && Objects.equals(workFlowEnum, WorkFlowEnum.QUOTATION_CANCEL_ARCHIVED)) {
                continue;
            }
            TopPermissionsPoJo topPermissionsPoJo = new TopPermissionsPoJo();
            BeanUtil.copyProperties(workFlowEnum, topPermissionsPoJo);
            if (Objects.equals(workFlowEnum.getFormRelation(), BasicConstant.ONE)) {
                changeValue(paasBusinessTypeToName, topPermissionsPoJo);
            }
            topPermissions.add(topPermissionsPoJo);
        }
        if (!Objects.equals(isNew, BasicConstant.ONE)) {
            // 不是最新版本的报价单不能编辑
            topPermissions.removeIf(item -> Objects.equals(item.getAttr(), OperateTypeEnum.EDIT.getAlias()));
        }
        List<LinkListPojo> linkList = formEntity.getLinkListList();
        topPermissions.addAll(linkListService.getDingtalkCommonButton(linkList, formData.getDel(), userVO, formData.getAppId(), formData.getFormId(), businessType, formEntity.getSaasMark(), corpid));
        return topPermissions;
    }

    @Override
    public List<ButtonPojo> handleDetailButton(FormDataDetailDTO formDataDetailDTO, HandelDetailPojo handelDetailPojo, PaasFormDataEntityExt formData, Map<String, FieldAttrEntity> explainMap) throws XbbException {
        JSONObject dataList = formData.getData();
        Object isNew = dataList.get(QuotationEnum.IS_NEW.getAttr());
        if (isNew == null) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100002);
        }
        List<ButtonPojo> buttonPojoList = handelDetailPojo.getButtonPojoList();
        UserVO userVO = handelDetailPojo.getLoginUser();
        Integer businessType = handelDetailPojo.getBusinessType();
        List<BusinessDetailButtonEnum> buttonEnumList = BusinessDetailButtonEnum.getByBusinessTypeAndPermission(businessType, userVO.getPermSet());
        VerifyViewPermissionDTO verifyViewPermissionDTO = new VerifyViewPermissionDTO(userVO, formData);
        boolean perTag = commonPermissionHelp.checkEditPermissionWithoutShareEdit(formDataDetailDTO, verifyViewPermissionDTO, explainMap);

        for (BusinessDetailButtonEnum buttonEnum : buttonEnumList) {
            if (Objects.equals(buttonEnum, BusinessDetailButtonEnum.QUOTATION_EDIT)) {
                if (Objects.equals(isNew, BasicConstant.ZERO)) {
                    continue;
                }
            }

            ButtonPojo buttonPojo = new ButtonPojo();
            SaasButtonEnum saasButtonEnum = buttonEnum.getAnEnum();
            if (!perTag && Objects.equals(SaasButtonEnum.EDIT.getAttr(), saasButtonEnum.getAttr())) {
                continue;
            }
            BeanUtil.copyProperties(saasButtonEnum, buttonPojo);
            buttonPojo.setLinkBusinessType(buttonEnum.getLinkBusinessType());
            buttonPojoList.add(buttonPojo);
        }
        return buttonPojoList;
    }

    @Override
    public List<WorkFlowPojo> webHandleDetailWorkFlow(HandelDetailPojo handelDetailPojo, PaasFormEntityExt formEntity, PaasFormDataEntityExt formData) throws XbbException {
        UserVO userVO = handelDetailPojo.getLoginUser();
        Set<String> permSet = userVO.getPermSet();
        List<WorkFlowEnum> workFlowEnumList = WorkFlowEnum.getByBusinessTypeAndPermission(handelDetailPojo.getBusinessType(), userVO.getPermSet());
        // 获取对应businessType的alias
        List<String> aliasIn = WorkFlowEnum.getAliasIn(workFlowEnumList);
        String corpid = formData.getCorpid();
        Integer businessType = handelDetailPojo.getBusinessType();

        Map<Integer, String> paasBusinessTypeToName = paasMenuModel.getMenuNameByAlias(aliasIn, corpid, businessType);

        List<WorkFlowPojo> workFlowPojoList = new ArrayList<>();
        for (WorkFlowEnum workFlowEnum : workFlowEnumList) {

            if (esignHelp.addEsignWorkFlow(permSet, workFlowPojoList, workFlowEnum,
                    XbbRefTypeEnum.QUOTATION, formData)) {
                continue;
            }

            WorkFlowPojo workFlowPojo = new WorkFlowPojo();
            BeanUtil.copyProperties(workFlowEnum, workFlowPojo);
            changeValue(paasBusinessTypeToName, workFlowPojo);
            workFlowPojoList.add(workFlowPojo);
        }
        List<LinkListPojo> linkList = JSONArray.parseArray(formEntity.getAssociationList(), LinkListPojo.class);
        workFlowPojoList.addAll(linkListService.getCommonButton(linkList, formData.getDel(), handelDetailPojo.getLoginUser(), formData.getAppId(), formData.getFormId(), handelDetailPojo.getBusinessType(), formEntity.getSaasMark(), corpid));
        return workFlowPojoList;
    }

    @Override
    public DataDetailPojo handleDetailData(Integer businessType, PaasFormDataEntityExt formData, String userId, HandlerExplainDTO handlerExplainDTO) throws XbbException {
        DataDetailPojo dataDetailPojo = new DataDetailPojo();
        // 外链
        Integer outerLinkShare = setOuterLinkShare(handlerExplainDTO.getCorpid(), formData.getFormId());
        dataDetailPojo.setHasOuterLinkShare(outerLinkShare);
        return dataDetailPojo;
    }


    @Override
    public JSONArray getSecondTitleList(FormDataDetailDTO formDataDetailDTO, PaasFormDataEntityExt formData, PaasFormEntityExt formEntity, List<FieldAttrEntity> list, Map<String, FieldAttrEntity> explainMap, JSONObject data) throws XbbException {
        List<SummaryDataPoJo> summaryList = getSummaryList(formDataDetailDTO, formData, formEntity, list, explainMap, data);
        return getSecondTitleList(summaryList, data, formDataDetailDTO.getCorpid(), formEntity.getId());
    }

    @Override
    public JSONArray getTagList(FormDataDetailDTO formDataDetailDTO, PaasFormDataEntityExt formData, PaasFormEntityExt formEntity, List<FieldAttrEntity> list, Map<String, FieldAttrEntity> explainMap, JSONObject data) throws XbbException {
        String corpid = formDataDetailDTO.getCorpid();
        Integer businessType = formEntity.getBusinessType();
        Long dataId = formData.getId();
        String userId = formDataDetailDTO.getUserId();
        List<SummaryDataPoJo> labelsList = getLabelList(formDataDetailDTO, formData, formEntity, list, explainMap, data);
        return getTags(labelsList, corpid, businessType, dataId, userId);
    }

    @Override
    public String getTitle(FormDataDetailDTO formDataDetailDTO, PaasFormDataEntityExt formData, PaasFormEntityExt formEntity, List<FieldAttrEntity> list, Map<String, FieldAttrEntity> explainMap, JSONObject data) throws XbbException {
        List<FormTitlePoJo> formTitleList = getTitleList(formDataDetailDTO, formData, formEntity, list, explainMap, data);
        return TitleUtil.getWebTitle(formTitleList);
    }




}
